home *** CD-ROM | disk | FTP | other *** search
/ Chip 2000 November / Chip Kasım 2000.iso / prog / share / 11 / setup.exe / %MAINDIR% / DEMOS / CIHTTP / HTTPEXP / files.bas < prev    next >
Encoding:
BASIC Source File  |  2000-09-07  |  9.5 KB  |  260 lines

  1. Attribute VB_Name = "FileSystem"
  2. '--------------------------------------------------------
  3. '<Purpose> provides support for the local file system
  4. '--------------------------------------------------------
  5.  
  6. Option Explicit
  7.  
  8. '----------------------------------------------------------------
  9. '<Purpose> returns the appropriate image number for a drive type
  10. '----------------------------------------------------------------
  11. Public Function GetDriveImage(DriveLetter As String) As Integer
  12.     Dim LegalDrive As String
  13.     
  14.     LegalDrive = DriveLetter & ":\"
  15.     
  16.     '---- some drives are not supported here
  17.     Select Case GetDriveType(LegalDrive)
  18.         Case DRIVE_CDROM
  19.             GetDriveImage = imgCDRom
  20.         Case DRIVE_FIXED
  21.             GetDriveImage = imgDriveNotShared
  22.         Case DRIVE_REMOTE
  23.             GetDriveImage = imgNetDrive
  24.         Case DRIVE_REMOVABLE
  25.             GetDriveImage = imgFloppyDrive
  26.         Case Else
  27.             GetDriveImage = DRIVE_UNIDENTIFIED
  28.     End Select
  29.     
  30. End Function
  31.  
  32. '------------------------------------------------------------
  33. '<Purpose> removes a recently disconnected network drive
  34. '------------------------------------------------------------
  35. Public Sub RemoveNetDrive(ThisExplorer As Form, ParentNode As Node)
  36.     Dim WorkingNode     As Node
  37.     Dim i               As Integer
  38.     Dim DriveImage      As Integer
  39.     Dim NumberChildren  As Integer
  40.     Dim DriveLetter     As String * 1
  41.     
  42.     NumberChildren = ParentNode.Children
  43.     For i = 1 To NumberChildren
  44.         If (i = 1) Then
  45.             Set WorkingNode = ParentNode.Child
  46.         Else
  47.             Set WorkingNode = WorkingNode.Next
  48.         End If
  49.     
  50.         '---- calculate the drive letter
  51.         DriveLetter = Mid(WorkingNode.Text, 2, 1)
  52.         DriveImage = GetDriveImage(DriveLetter)
  53.         
  54.         '---- see if the drive is unidentified, and remove it
  55.         If (DriveImage = DRIVE_UNIDENTIFIED) Then
  56.             Call ThisExplorer.Tree.Nodes.Remove(WorkingNode.Key)
  57.             
  58.             '---- also remove the extra data
  59.             Call ThisExplorer.Attachments.Remove(WorkingNode.Key)
  60.             
  61.             Exit Sub
  62.         End If
  63.     Next
  64.     
  65.     Set WorkingNode = Nothing
  66. End Sub
  67.  
  68. '------------------------------------------------------------
  69. '<Purpose> populates the ListView with local files
  70. ' under a directory
  71. '------------------------------------------------------------
  72. Public Sub AddLocalFiles(ThisExplorer As Form, ParentNode As Node)
  73.     Dim TheseItems      As ListItems
  74.     Dim WorkingItem     As ListItem
  75.     Dim FileAttr        As Integer
  76.     Dim FileName        As String
  77.     Dim FileType        As String
  78.     Dim FullPathName    As String
  79.     Dim StartingDir     As String
  80.  
  81.     ThisExplorer.MousePointer = vbHourglass
  82.     
  83.     On Error GoTo BadItem
  84.     
  85.     '---- cache the ListItems collection
  86.     Set TheseItems = ThisExplorer.List.ListItems
  87.             
  88.     StartingDir = ThisExplorer.Attachments(ParentNode.Key).DrivePath
  89.     FileName = Dir(StartingDir)
  90.  
  91.     Do While (FileName <> "")
  92.         If ((FileName <> ".") And (FileName <> "..")) Then
  93.             FullPathName = StartingDir & FileName
  94.             
  95.             FileAttr = GetAttr(FullPathName)            ' Get Files Attributes...
  96.             If (FileAttr <> vbDirectory) Then
  97.                 '---- add file to ListView
  98.                 Set WorkingItem = TheseItems.Add(, FullPathName, FileName, imgLocalFile, imgLocalFile)
  99.                 FileType = "File"
  100.             Else
  101.                 '---- add directory to ListView
  102.                 Set WorkingItem = TheseItems.Add(, FullPathName, FileName, imgFolderClosed, imgFolderClosed)
  103.                 FileType = "File Folder"
  104.             End If
  105.             
  106.             '---  add type, size, and modified bits
  107.             WorkingItem.SubItems(1) = Str(FileLen(FullPathName) \ 1024) & "KB"
  108.             WorkingItem.SubItems(2) = FileType
  109.             WorkingItem.SubItems(3) = Format(FileDateTime(FullPathName), "General Date")
  110.         End If
  111.         
  112. NextDir:
  113.         '---- dir with no arguments gets next file, or directory
  114.         FileName = Dir
  115.     Loop
  116.  
  117. Cleanup:
  118.     On Error GoTo 0
  119.     Set TheseItems = Nothing
  120.     Set WorkingItem = Nothing
  121.     ThisExplorer.MousePointer = vbDefault
  122.     Exit Sub
  123.     
  124. BadItem:
  125.     Resume NextDir
  126. End Sub
  127.  
  128. '------------------------------------------------------------
  129. '<Purpose> populates the TreeView with local directories
  130. ' under a particular drive or directory
  131. '------------------------------------------------------------
  132. Public Sub AddLocalDirs(ThisExplorer As Form, ParentNode As Node)
  133.     Dim TheseItems      As ListItems
  134.     Dim WorkingItem     As ListItem
  135.     Dim WorkingNode     As Node
  136.     Dim TheseNodes      As Nodes
  137.     Dim FileAttr        As Integer
  138.     Dim DirName         As String
  139.     Dim FullPathName    As String
  140.     Dim NodeKey         As String
  141.     Dim StartingDir     As String
  142.     
  143.     ThisExplorer.MousePointer = vbHourglass
  144.     
  145.     On Error GoTo BadNode
  146.     
  147.     '---- cache nodes and list items collections
  148.     Set TheseNodes = ThisExplorer.Tree.Nodes
  149.     Set TheseItems = ThisExplorer.List.ListItems
  150.     
  151.     TheseItems.Clear
  152.     
  153.     StartingDir = ThisExplorer.Attachments(ParentNode.Key).DrivePath
  154.     
  155.     '---- get all directories under the starting directory
  156.     DirName = Dir(StartingDir, vbDirectory)
  157.     Do While (DirName <> "")
  158.         '---- ignore current and previous directories
  159.         If ((DirName <> ".") And (DirName <> "..")) Then
  160.             FullPathName = StartingDir & DirName
  161.             FileAttr = GetAttr(FullPathName)
  162.             If (FileAttr = vbDirectory) Then
  163.                 NodeKey = ParentNode.Key & "." & DirName
  164.                 
  165.                 If (Not IsKeyed(TheseNodes, NodeKey)) Then
  166.                     '---- add the node to the tree
  167.                     Set WorkingNode = TheseNodes.Add(ParentNode, tvwChild, NodeKey, DirName, imgFolderClosed, imgFolderOpen)
  168.                 
  169.                     '---- also create and add attachment
  170.                     Dim ThisAttachment As New Attachment
  171.                     ThisAttachment.NodeType = nodLocalDrive
  172.                     ThisAttachment.DrivePath = StartingDir & DirName & "\"
  173.                     Call ThisExplorer.Attachments.Add(ThisAttachment, NodeKey)
  174.                     Set ThisAttachment = Nothing
  175.                     
  176.                     '---- add searching placeholder
  177.                     Call TheseNodes.Add(WorkingNode, tvwChild, WorkingNode.Key & nodPlaceHolder, nodPlaceHolder, imgPlaceHolder)
  178.                 End If
  179.                 
  180.                 '---- add directory to ListView; pad with invisible char for sorting purposes
  181.                 Set WorkingItem = TheseItems.Add(, NodeKey, Chr(160) & DirName, imgFolderClosed, imgFolderClosed)
  182.                 '---  add type, size, and modified bits to item
  183.                 'WorkingItem.SubItems(1) = Str(FileLen(FullPathName) \ 1024) & "KB"
  184.                 WorkingItem.SubItems(2) = "File Folder"
  185.                 WorkingItem.SubItems(3) = Format(FileDateTime(FullPathName), "General Date")
  186.             End If
  187.         End If
  188.         '---- dir with no arguments gets next file, or directory
  189.         DirName = Dir
  190.     Loop
  191.     
  192. Cleanup:
  193.     On Error GoTo 0
  194.     Set TheseItems = Nothing
  195.     Set TheseNodes = Nothing
  196.     Set WorkingItem = Nothing
  197.     Set WorkingNode = Nothing
  198.     ThisExplorer.MousePointer = vbDefault
  199.     Exit Sub
  200.     
  201. BadNode:
  202.     GoTo Cleanup
  203. End Sub
  204.  
  205. '------------------------------------------------------------
  206. '<Purpose> populates the TreeView with local drives
  207. '------------------------------------------------------------
  208. Public Sub AddLocalDrives(ThisExplorer As Form, ParentNode As Node)
  209.     Dim DriveImage      As Integer
  210.     Dim DriveID         As Long
  211.     Dim TheseNodes      As Nodes
  212.     Dim WorkingNode     As Node
  213.     Dim DriveLetter     As String * 1
  214.     Dim NodeKey         As String
  215.     Dim ParentKey       As String
  216.     
  217.     ThisExplorer.MousePointer = vbHourglass
  218.     
  219.     '---- errors can be generated from duplicate keys; ignore
  220.     On Error Resume Next
  221.     
  222.     '---- cache nodes collection
  223.     Set TheseNodes = ThisExplorer.Tree.Nodes
  224.     
  225.     ParentKey = ParentNode.Key & "."
  226.     
  227.     For DriveID = Asc("A") To Asc("Z")
  228.         DriveLetter = Chr(DriveID)
  229.         NodeKey = ParentKey & DriveLetter
  230.         
  231.         If (Not IsKeyed(TheseNodes, NodeKey)) Then
  232.             DriveImage = GetDriveImage(DriveLetter)
  233.             
  234.             If (Not (DriveImage = DRIVE_UNIDENTIFIED)) Then
  235.                 '---- add the node to the tree
  236.                 Set WorkingNode = TheseNodes.Add(ParentNode, tvwChild, NodeKey, "(" & DriveLetter & ":" & ")", DriveImage)
  237.                 
  238.                 '---- also create and add attachment
  239.                 Dim ThisAttachment As New Attachment
  240.                 ThisAttachment.NodeType = nodLocalDrive
  241.                 ThisAttachment.DrivePath = DriveLetter & ":\"
  242.                 Call ThisExplorer.Attachments.Add(ThisAttachment, NodeKey)
  243.                 Set ThisAttachment = Nothing
  244.                                 
  245.                 '---- add searching placeholder
  246.                 Call TheseNodes.Add(WorkingNode, tvwChild, WorkingNode.Key & nodPlaceHolder, nodPlaceHolder, imgPlaceHolder)
  247.             End If
  248.         End If
  249.         
  250.     Next DriveID
  251.     
  252. Cleanup:
  253.     On Error GoTo 0
  254.     Set TheseNodes = Nothing
  255.     Set WorkingNode = Nothing
  256.     ThisExplorer.MousePointer = vbDefault
  257. End Sub
  258.  
  259.  
  260.